﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;
using System.Deployment.Application;

namespace ParsecClient.Classes
{
    public class TimerDefinitionCollection
    {
        public List<TimerDefinition> Timers { get; set; }
        private static string TimerDefinitionFileName = "TimerDefinitions.xml";
        private static System.Xml.Serialization.XmlSerializer TimerDefinitionFileSerializer = new System.Xml.Serialization.XmlSerializer(typeof(TimerDefinitionCollection));
        public static void SaveTimerDefinitions(List<TimerDefinition> d)
        {
            string fullPath = Serializer.GetFullPath(TimerDefinitionFileName);
            TimerDefinitionCollection tdc = new TimerDefinitionCollection() { Timers = d };
            Serializer.SerializeDataToDisk(TimerDefinitionFileSerializer, tdc, fullPath);
        }
        public static List<TimerDefinition> RetrieveTimerDefinitions()
        {
            string fullPath = Serializer.GetFullPath(TimerDefinitionFileName);
            if (File.Exists(fullPath))
            {
                TimerDefinitionCollection csc = (TimerDefinitionCollection)Serializer.DeserializeDataFromDisk(TimerDefinitionFileSerializer, fullPath, false);
                return csc == null ? new List<TimerDefinition>() : csc.Timers;
            }
            else
                return new List<TimerDefinition>();
        }
        public static void DeleteAllTimerDefinition()
        {
            string fullPath = Serializer.GetFullPath(TimerDefinitionFileName);
            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }
        }
    }
}
